package com.sdlh.demo.pattern.strategy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/payment")
public class PayController {
    @Autowired
    private PaymentContext paymentContext;

    @Autowired
    private PaymentStrategyFactory factory;

    @PostMapping("/pay")
    public void pay(int payType, double amount) {
//        paymentContext.setStrategy(payType);
//        paymentContext.pay(amount);
        factory.getStrategy(payType)
               .commonPay(amount);
    }
}
